package com.wedu.service.impl;

import com.wedu.dao.StudentDao;
import com.wedu.dao.impl.StudentDaoImpl;
import com.wedu.entity.Student;
import com.wedu.service.StudentService;

import java.sql.SQLException;


public class StudentServiceImpl implements StudentService {

    //创建StudentDaoImpl对象
    private StudentDao studentDao = new StudentDaoImpl();

    //    用户登录
    @Override
    public boolean loginStu(String name, String password) {
        if (name == null || password == null) {
            return false;
        }
        Student login = studentDao.login(name, password);
        if (login != null) {
            return true;
        } else
            return false;
    }

    //    用户注册
    @Override
    public int registerStu(String name, String password) {
        int register = 0;
        if (name == null || password == null) {
            System.out.println("输入内容为空");
        } else {
            register = studentDao.register(name, password);
        }
        return register;
    }

    //    用户修改
    public boolean updateMsgStu(Student student) throws SQLException {
        if (student == null) {
            return false;
        }
         studentDao.updateMsg(student);
            return true;
    }

    @Override
    public boolean updateMsgStu(int id, String name, String sex, int age, String password) throws SQLException {
        Student student = new Student();
        student.setId(id);
        student.setName(name);
        student.setSex(sex);
        student.setAge(age);
        student.setPassword(password);

        studentDao.updateMsg(student);
       if(student != null){
         return true;
        }
       return false;
    }


}